<template>
  <div class="app-container" style="padding: 5px;">
    <el-form :inline="true" :model="queryForm" class="demo-form-inline">
      <el-form-item style="margin-bottom:10px;">
        <el-input v-model="queryForm.keywords" prefix-icon="el-icon-search" placeholder="POI名称" style="width: 14.5rem"
          @input="onQuerySubmit" />
      </el-form-item>
      <el-form-item style="margin-bottom: 10px">
        <el-button type="primary" icon="el-icon-plus" @click="handleAdd">添加模板</el-button>
      </el-form-item>
    </el-form>

    <el-table :data="tableData" border empty-text="暂无数据." style="width: 100%">
      <el-table-column type="selection" width="40">
      </el-table-column>
      <el-table-column type="index" label="序号" width="50" align="center" :index="indexMethod">
      </el-table-column>

      <el-table-column prop="status" label="图标" width="150px" align="center">
         <template slot-scope="scope">
           <el-image
               style="width: 120px; height: 90px"
               fit="fit"
               :src="scope.row.url"
               >
           </el-image>
         </template>
       </el-table-column>

      <el-table-column prop="markerNormalSize" label="图标尺寸">
      </el-table-column>

      <el-table-column label="操作" width="130" align="center">
        <template slot-scope="scope">
          <el-button type="text" size="small" @click="handleEdit(scope.row)">编辑
          </el-button>
          <el-button type="text" size="small" @click="handleDelete(scope.row)">删除
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-row>
      <el-col :span="24">
        <div align="right" style="margin-top: 0.3125rem;">
          <el-pagination background layout="prev, pager, next" :current-page="page.cur" :page-size="page.limit"
            :total="page.total" @current-change="handleCurrentChange" />
        </div>
      </el-col>
    </el-row>
    <!--编辑框-->
    <info-drawer v-if="editDrawer.visible" :properties="editDrawer" @closed="close" @refresh="load" />
  </div>
</template>

<script>
  import InfoDrawer from './components/InfoDrawer.vue'
  import {
    findPoiStyleList,
    deletePoiStyle,
  } from '@/api/subsystem/poiTemplate'
  import {
    isOk
  } from '@/utils/request'
  export default {
    name: 'POIStyle',
    components: {
      InfoDrawer,
    },
    computed: {

    },
    data() {
      return {
        loading: false,
        baseUrl:process.env.VUE_APP_BASE_API,
        queryForm: {
          keywords: undefined,
        },
        page: {
          cur: 1,
          limit: 50,
          total: 0
        },
        tableData: [],
        editDrawer: {
          visible: false,
          type: '0',
          data: {}
        },
      }
    },
    created() {
      this.load()
    },
    methods: {
      indexMethod(index) {
        return index + 1;
      },
      onQuerySubmit(event) {
        this.load()
      },
      onReset(event) {
        this.queryForm.keywords = undefined;
        this.queryForm.status = '';
        this.load()
      },
      load() {
        this.loading = true
        findPoiStyleList({
            projectId: this.$store.getters.projectId,
            cur: this.page.cur,
            limit: this.page.limit,
            keywords: this.queryForm.keywords,
          }).then(rsp => {
            if (isOk(rsp)) {
              const _data = rsp.result
              console.log(_data)
              this.page.total = _data.totalRow
              _data.list.forEach(item => {
                item['url']=this.baseUrl+'/biz/scene/thumbnail/'+item.id+'_normal'
              })
              this.tableData = _data.list
              this.loading = false
            }
          }).catch(err => {
            console.log(err);
          })
          .finally(() => {
            this.loading = false
          })
      },
      handleCurrentChange(cur) {
        this.page.cur = cur
        this.load()
      },
      handleAdd: function(e) {
        this.editDrawer.visible = true
        this.editDrawer.type = '0'
      },
      handleEdit: function(data) {
        this.editDrawer.visible = true
        this.editDrawer.type = '1'
        this.editDrawer.data = data
      },
      close: function(e) {
        this.editDrawer.visible = false
        this.editDrawer.data = {}
        this.load()
      },
      handleDelete: function(data) {
        this.$confirm('确认删除吗？', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.loading = true
          deletePoiStyle({
              id: data.id
            }).then(response => {
              this.$message({
                message: '删除成功',
                type: 'success',
                duration: 500
              })
              this.load()
            }).catch(err => {
              console.log(err);
            })
            .finally(() => {
              this.loading = false
            })
        })
      },
    }
  }
</script>
<style scoped>
  /deep/.el-card__header {
    padding-top: 10px;
    padding-bottom: 10px;
  }

  /deep/.layer-card .el-card__body {
    padding: 5px;
  }
</style>
